package cn.lhl.web.exceptions;

import org.apache.shiro.authz.UnauthorizedException;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class CustomerExceptionResolver implements HandlerExceptionResolver {
    public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {
        if (ex instanceof UnauthorizedException){
            return new ModelAndView("forward:/unauthorized.jsp");
        }

        ModelAndView mv = new ModelAndView();

        //  WEB-INF/pages/error.jsp
        mv.setViewName("error");
        mv.addObject("errorMsg", "对不起，我错了！");

        return mv;
    }
}
